WPS Office.apk(点击下载) / wrq.java


package defpackage;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Parcel;
import android.os.StatFs;
import android.support.v4.app.NotificationCompat;
import android.support.v4.os.EnvironmentCompat;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.view.autofill.AutofillManager;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import com.baidu.tts.loopj.AsyncHttpResponseHandler;
import com.facebook.AccessToken;
import com.facebook.GraphRequest;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.iflytek.cloud.SpeechEvent;
import com.mopub.common.Constants;
import com.mopub.nativeads.KS2SEventNative;
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Pattern;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.scribe.model.OAuthConstants;

/* renamed from: wrq  reason: default package */
public final class wrq {
    private static int xna = 0;
    private static long xnb = -1;
    private static long xnc = -1;
    private static long xnd = -1;
    private static String xne = "";
    private static String xnf = "";
    private static String xng = "NoCarrier";

    /* renamed from: wrq$a */
    public interface a {
        void W(JSONObject jSONObject);

        void b(woz woz);
    }

    /* renamed from: wrq$b */
    public static class b {
        public List<String> xni;
        public List<String> xnj;

        public b(List<String> list, List<String> list2) {
            this.xni = list;
            this.xnj = list2;
        }
    }

    public static String W(InputStream inputStream) throws IOException {
        InputStreamReader inputStreamReader;
        BufferedInputStream bufferedInputStream = null;
        try {
            BufferedInputStream bufferedInputStream2 = new BufferedInputStream(inputStream);
            try {
                inputStreamReader = new InputStreamReader(bufferedInputStream2);
                try {
                    StringBuilder sb = new StringBuilder();
                    char[] cArr = new char[2048];
                    while (true) {
                        int read = inputStreamReader.read(cArr);
                        if (read != -1) {
                            sb.append(cArr, 0, read);
                        } else {
                            String sb2 = sb.toString();
                            closeQuietly(bufferedInputStream2);
                            closeQuietly(inputStreamReader);
                            return sb2;
                        }
                    }
                } catch (Throwable th) {
                    th = th;
                    bufferedInputStream = bufferedInputStream2;
                    closeQuietly(bufferedInputStream);
                    closeQuietly(inputStreamReader);
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
                inputStreamReader = null;
                bufferedInputStream = bufferedInputStream2;
                closeQuietly(bufferedInputStream);
                closeQuietly(inputStreamReader);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            inputStreamReader = null;
            closeQuietly(bufferedInputStream);
            closeQuietly(inputStreamReader);
            throw th;
        }
    }

    public static JSONObject YA(String str) {
        JSONObject Yw = wrm.Yw(str);
        if (Yw != null) {
            return Yw;
        }
        wph gaB = YB(str).gaB();
        if (gaB.xhJ != null) {
            return null;
        }
        return gaB.xhP;
    }

    private static GraphRequest YB(String str) {
        Bundle bundle = new Bundle();
        bundle.putString("fields", "id,name,first_name,middle_name,last_name,link");
        bundle.putString(OAuthConstants.ACCESS_TOKEN, str);
        return new GraphRequest(null, "me", bundle, wpi.GET, null);
    }

    public static boolean Yx(String str) {
        return str == null || str.length() == 0;
    }

    public static String Yy(String str) {
        return i("MD5", str.getBytes());
    }

    public static Bundle Yz(String str) {
        Bundle bundle = new Bundle();
        if (!Yx(str)) {
            for (String str2 : str.split("&")) {
                String[] split = str2.split("=");
                try {
                    if (split.length == 2) {
                        bundle.putString(URLDecoder.decode(split[0], AsyncHttpResponseHandler.DEFAULT_CHARSET), URLDecoder.decode(split[1], AsyncHttpResponseHandler.DEFAULT_CHARSET));
                    } else if (split.length == 1) {
                        bundle.putString(URLDecoder.decode(split[0], AsyncHttpResponseHandler.DEFAULT_CHARSET), "");
                    }
                } catch (UnsupportedEncodingException e) {
                    a("FacebookSDK", e);
                }
            }
        }
        return bundle;
    }

    public static Date a(Bundle bundle, String str, Date date) {
        long parseLong;
        if (bundle == null) {
            return null;
        }
        Object obj = bundle.get(str);
        if (obj instanceof Long) {
            parseLong = ((Long) obj).longValue();
        } else if (!(obj instanceof String)) {
            return null;
        } else {
            try {
                parseLong = Long.parseLong((String) obj);
            } catch (NumberFormatException e) {
                return null;
            }
        }
        if (parseLong == 0) {
            return new Date(Long.MAX_VALUE);
        }
        return new Date((parseLong * 1000) + date.getTime());
    }

    public static void a(Bundle bundle, String str, Uri uri) {
        if (uri != null) {
            a(bundle, str, uri.toString());
        }
    }

    public static void a(Bundle bundle, String str, String str2) {
        if (!Yx(str2)) {
            bundle.putString(str, str2);
        }
    }

    public static void a(Parcel parcel, Map<String, String> map) {
        if (map == null) {
            parcel.writeInt(-1);
            return;
        }
        parcel.writeInt(map.size());
        for (Map.Entry<String, String> entry : map.entrySet()) {
            parcel.writeString(entry.getKey());
            parcel.writeString(entry.getValue());
        }
    }

    public static void a(String str, Exception exc) {
        if (wpc.isDebugEnabled() && str != null && exc != null) {
            Log.d(str, exc.getClass().getSimpleName() + ": " + exc.getMessage());
        }
    }

    public static void a(final String str, final a aVar) {
        JSONObject Yw = wrm.Yw(str);
        if (Yw != null) {
            aVar.W(Yw);
            return;
        }
        AnonymousClass1 r0 = new GraphRequest.b() {
            /* class defpackage.wrq.AnonymousClass1 */

            @Override // com.facebook.GraphRequest.b
            public final void a(wph wph) {
                if (wph.xhJ != null) {
                    aVar.b(wph.xhJ.xhk);
                    return;
                }
                wrm.d(str, wph.xhP);
                aVar.W(wph.xhP);
            }
        };
        GraphRequest YB = YB(str);
        YB.a(r0);
        YB.gaC();
    }

    public static void a(URLConnection uRLConnection) {
        if (uRLConnection != null && (uRLConnection instanceof HttpURLConnection)) {
            ((HttpURLConnection) uRLConnection).disconnect();
        }
    }

    public static void a(JSONObject jSONObject, wqo wqo, String str, boolean z) throws JSONException {
        boolean z2 = true;
        if (!(wqo == null || wqo.xkB == null)) {
            jSONObject.put("attribution", wqo.xkB);
        }
        if (!(wqo == null || wqo.xkC == null)) {
            jSONObject.put("advertiser_id", wqo.xkC);
            jSONObject.put("advertiser_tracking_enabled", !wqo.xkE);
        }
        if (!(wqo == null || wqo.xkD == null)) {
            jSONObject.put("installer_package", wqo.xkD);
        }
        jSONObject.put("anon_id", str);
        if (z) {
            z2 = false;
        }
        jSONObject.put("application_tracking_enabled", z2);
    }

    public static String aC(byte[] bArr) {
        return i("SHA-1", bArr);
    }

    public static b aa(JSONObject jSONObject) throws JSONException {
        String optString;
        JSONArray jSONArray = jSONObject.getJSONObject("permissions").getJSONArray(SpeechEvent.KEY_EVENT_RECORD_DATA);
        ArrayList arrayList = new ArrayList(jSONArray.length());
        ArrayList arrayList2 = new ArrayList(jSONArray.length());
        for (int i = 0; i < jSONArray.length(); i++) {
            JSONObject optJSONObject = jSONArray.optJSONObject(i);
            String optString2 = optJSONObject.optString("permission");
            if (!(optString2 == null || optString2.equals("installed") || (optString = optJSONObject.optString(NotificationCompat.CATEGORY_STATUS)) == null)) {
                if (optString.equals("granted")) {
                    arrayList.add(optString2);
                } else if (optString.equals("declined")) {
                    arrayList2.add(optString2);
                }
            }
        }
        return new b(arrayList, arrayList2);
    }

    public static String aqi(int i) {
        return new BigInteger(100, new Random()).toString(32);
    }

    public static Object b(Object obj, Method method, Object... objArr) {
        try {
            return method.invoke(obj, objArr);
        } catch (IllegalAccessException | InvocationTargetException e) {
            return null;
        }
    }

    public static Object b(JSONObject jSONObject, String str, String str2) throws JSONException {
        Object opt = jSONObject.opt(str);
        Object nextValue = (opt == null || !(opt instanceof String)) ? opt : new JSONTokener((String) opt).nextValue();
        if (nextValue == null || (nextValue instanceof JSONObject) || (nextValue instanceof JSONArray)) {
            return nextValue;
        }
        if (str2 != null) {
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.putOpt(str2, nextValue);
            return jSONObject2;
        }
        throw new woz("Got an unexpected non-JSON object.");
    }

    public static Map<String, String> b(Parcel parcel) {
        int readInt = parcel.readInt();
        if (readInt < 0) {
            return null;
        }
        HashMap hashMap = new HashMap();
        for (int i = 0; i < readInt; i++) {
            hashMap.put(parcel.readString(), parcel.readString());
        }
        return hashMap;
    }

    public static void b(JSONObject jSONObject, Context context) throws JSONException {
        Locale locale;
        int i;
        int i2;
        int i3;
        int i4;
        double d;
        JSONArray jSONArray = new JSONArray();
        jSONArray.put("a2");
        if (xnb == -1 || System.currentTimeMillis() - xnb >= 1800000) {
            xnb = System.currentTimeMillis();
            gbR();
            iB(context);
            gbU();
            gbT();
        }
        String packageName = context.getPackageName();
        int i5 = -1;
        String str = "";
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
            i5 = packageInfo.versionCode;
            str = packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
        }
        jSONArray.put(packageName);
        jSONArray.put(i5);
        jSONArray.put(str);
        jSONArray.put(Build.VERSION.RELEASE);
        jSONArray.put(Build.MODEL);
        try {
            locale = context.getResources().getConfiguration().locale;
        } catch (Exception e2) {
            locale = Locale.getDefault();
        }
        jSONArray.put(locale.getLanguage() + "_" + locale.getCountry());
        jSONArray.put(xne);
        jSONArray.put(xng);
        try {
            WindowManager windowManager = (WindowManager) context.getSystemService("window");
            if (windowManager != null) {
                Display defaultDisplay = windowManager.getDefaultDisplay();
                DisplayMetrics displayMetrics = new DisplayMetrics();
                defaultDisplay.getMetrics(displayMetrics);
                int i6 = displayMetrics.widthPixels;
                try {
                    int i7 = displayMetrics.heightPixels;
                    try {
                        d = (double) displayMetrics.density;
                        i3 = i7;
                        i4 = i6;
                    } catch (Exception e3) {
                        i2 = i7;
                        i = i6;
                        i3 = i2;
                        i4 = i;
                        d = 0.0d;
                        jSONArray.put(i4);
                        jSONArray.put(i3);
                        jSONArray.put(String.format("%.2f", Double.valueOf(d)));
                        jSONArray.put(gbQ());
                        jSONArray.put(xnc);
                        jSONArray.put(xnd);
                        jSONArray.put(xnf);
                        jSONObject.put("extinfo", jSONArray.toString());
                    }
                } catch (Exception e4) {
                    i2 = 0;
                    i = i6;
                    i3 = i2;
                    i4 = i;
                    d = 0.0d;
                    jSONArray.put(i4);
                    jSONArray.put(i3);
                    jSONArray.put(String.format("%.2f", Double.valueOf(d)));
                    jSONArray.put(gbQ());
                    jSONArray.put(xnc);
                    jSONArray.put(xnd);
                    jSONArray.put(xnf);
                    jSONObject.put("extinfo", jSONArray.toString());
                }
            } else {
                d = 0.0d;
                i3 = 0;
                i4 = 0;
            }
        } catch (Exception e5) {
            i2 = 0;
            i = 0;
            i3 = i2;
            i4 = i;
            d = 0.0d;
            jSONArray.put(i4);
            jSONArray.put(i3);
            jSONArray.put(String.format("%.2f", Double.valueOf(d)));
            jSONArray.put(gbQ());
            jSONArray.put(xnc);
            jSONArray.put(xnd);
            jSONArray.put(xnf);
            jSONObject.put("extinfo", jSONArray.toString());
        }
        jSONArray.put(i4);
        jSONArray.put(i3);
        jSONArray.put(String.format("%.2f", Double.valueOf(d)));
        jSONArray.put(gbQ());
        jSONArray.put(xnc);
        jSONArray.put(xnd);
        jSONArray.put(xnf);
        jSONObject.put("extinfo", jSONArray.toString());
    }

    public static boolean b(Bundle bundle, String str, Object obj) {
        if (obj instanceof Boolean) {
            bundle.putBoolean(str, ((Boolean) obj).booleanValue());
            return true;
        } else if (obj instanceof Double) {
            bundle.putDouble(str, ((Double) obj).doubleValue());
            return true;
        } else if (obj instanceof Integer) {
            bundle.putInt(str, ((Integer) obj).intValue());
            return true;
        } else if (obj instanceof Long) {
            bundle.putLong(str, ((Long) obj).longValue());
            return true;
        } else if (obj instanceof String) {
            bundle.putString(str, (String) obj);
            return true;
        } else {
            bundle.putString(str, obj.toString());
            return true;
        }
    }

    public static void bu(File file) {
        File[] listFiles;
        if (file.exists()) {
            if (file.isDirectory() && (listFiles = file.listFiles()) != null) {
                for (File file2 : listFiles) {
                    bu(file2);
                }
            }
            file.delete();
        }
    }

    public static Method c(String str, String str2, Class<?>... clsArr) {
        try {
            return d(Class.forName(str), str2, clsArr);
        } catch (ClassNotFoundException e) {
            return null;
        }
    }

    private static long cO(double d) {
        return Math.round(d / 1.073741824E9d);
    }

    public static void closeQuietly(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
            }
        }
    }

    private static void cn(Context context, String str) {
        CookieSyncManager.createInstance(context).sync();
        CookieManager instance = CookieManager.getInstance();
        String cookie = instance.getCookie(str);
        if (cookie != null) {
            String[] split = cookie.split(";");
            for (String str2 : split) {
                String[] split2 = str2.split("=");
                if (split2.length > 0) {
                    instance.setCookie(str, split2[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;");
                }
            }
            instance.removeExpiredCookie();
        }
    }

    public static Uri d(String str, String str2, Bundle bundle) {
        Uri.Builder builder = new Uri.Builder();
        builder.scheme(Constants.HTTPS);
        builder.authority(str);
        builder.path(str2);
        if (bundle != null) {
            for (String str3 : bundle.keySet()) {
                Object obj = bundle.get(str3);
                if (obj instanceof String) {
                    builder.appendQueryParameter(str3, (String) obj);
                }
            }
        }
        return builder.build();
    }

    public static Method d(Class<?> cls, String str, Class<?>... clsArr) {
        try {
            return cls.getMethod(str, clsArr);
        } catch (NoSuchMethodException e) {
            return null;
        }
    }

    public static boolean d(AccessToken accessToken) {
        if (accessToken != null) {
            return accessToken.equals(AccessToken.gah());
        }
        return false;
    }

    public static <T> boolean e(Collection<T> collection) {
        return collection == null || collection.size() == 0;
    }

    public static String f(JSONObject jSONObject, String str) {
        return jSONObject != null ? jSONObject.optString(str, "") : "";
    }

    public static JSONObject g(JSONObject jSONObject, String str) {
        if (jSONObject != null) {
            return jSONObject.optJSONObject(str);
        }
        return null;
    }

    private static int gbQ() {
        if (xna > 0) {
            return xna;
        }
        try {
            File[] listFiles = new File("/sys/devices/system/cpu/").listFiles(new FilenameFilter() {
                /* class defpackage.wrq.AnonymousClass2 */

                public final boolean accept(File file, String str) {
                    return Pattern.matches("cpu[0-9]+", str);
                }
            });
            if (listFiles != null) {
                xna = listFiles.length;
            }
        } catch (Exception e) {
        }
        if (xna <= 0) {
            xna = Math.max(Runtime.getRuntime().availableProcessors(), 1);
        }
        return xna;
    }

    private static void gbR() {
        try {
            TimeZone timeZone = TimeZone.getDefault();
            xne = timeZone.getDisplayName(timeZone.inDaylightTime(new Date()), 0);
            xnf = timeZone.getID();
        } catch (Exception e) {
        }
    }

    private static boolean gbS() {
        return "mounted".equals(Environment.getExternalStorageState());
    }

    private static void gbT() {
        try {
            if (gbS()) {
                StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
                xnd = ((long) statFs.getBlockSize()) * ((long) statFs.getAvailableBlocks());
            }
            xnd = cO((double) xnd);
        } catch (Exception e) {
        }
    }

    private static void gbU() {
        try {
            if (gbS()) {
                StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
                xnc = ((long) statFs.getBlockSize()) * ((long) statFs.getBlockCount());
            }
            xnc = cO((double) xnc);
        } catch (Exception e) {
        }
    }

    public static JSONArray h(JSONObject jSONObject, String str) {
        if (jSONObject != null) {
            return jSONObject.optJSONArray(str);
        }
        return null;
    }

    public static String hv(String str, String str2) {
        return Yx(str) ? str2 : str;
    }

    public static void hw(String str, String str2) {
        if (wpc.isDebugEnabled() && str != null && str2 != null) {
            Log.d(str, str2);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:17:0x0025  */
    /* JADX WARNING: Removed duplicated region for block: B:19:0x002a  */
    public static int i(InputStream inputStream, OutputStream outputStream) throws IOException {
        BufferedInputStream bufferedInputStream;
        Throwable th;
        int i = 0;
        try {
            bufferedInputStream = new BufferedInputStream(inputStream);
            try {
                byte[] bArr = new byte[8192];
                while (true) {
                    int read = bufferedInputStream.read(bArr);
                    if (read == -1) {
                        break;
                    }
                    outputStream.write(bArr, 0, read);
                    i += read;
                }
                bufferedInputStream.close();
                if (inputStream != null) {
                    inputStream.close();
                }
                return i;
            } catch (Throwable th2) {
                th = th2;
                if (bufferedInputStream != null) {
                }
                if (inputStream != null) {
                }
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            bufferedInputStream = null;
            if (bufferedInputStream != null) {
                bufferedInputStream.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
            throw th;
        }
    }

    private static String i(String str, byte[] bArr) {
        try {
            MessageDigest instance = MessageDigest.getInstance(str);
            instance.update(bArr);
            byte[] digest = instance.digest();
            StringBuilder sb = new StringBuilder();
            for (byte b2 : digest) {
                sb.append(Integer.toHexString((b2 >> 4) & 15));
                sb.append(Integer.toHexString(b2 & 15));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }

    public static String iA(Context context) {
        return context == null ? "null" : context == context.getApplicationContext() ? EnvironmentCompat.MEDIA_UNKNOWN : context.getClass().getSimpleName();
    }

    private static void iB(Context context) {
        if (xng.equals("NoCarrier")) {
            try {
                xng = ((TelephonyManager) context.getSystemService("phone")).getNetworkOperatorName();
            } catch (Exception e) {
            }
        }
    }

    public static boolean iC(Context context) {
        return iD(context);
    }

    public static boolean iD(Context context) {
        if (Build.VERSION.SDK_INT < 26) {
            return false;
        }
        AutofillManager autofillManager = (AutofillManager) context.getSystemService(AutofillManager.class);
        return autofillManager != null && autofillManager.isAutofillSupported() && autofillManager.isEnabled();
    }

    public static String iy(Context context) {
        wrr.e(context, "context");
        wpc.io(context);
        return wpc.getApplicationId();
    }

    public static void iz(Context context) {
        cn(context, "facebook.com");
        cn(context, ".facebook.com");
        cn(context, "https://facebook.com");
        cn(context, "https://.facebook.com");
    }

    public static void k(String str, String str2, Throwable th) {
        if (wpc.isDebugEnabled() && !Yx(str)) {
            Log.d(str, str2, th);
        }
    }

    public static List<String> l(JSONArray jSONArray) throws JSONException {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < jSONArray.length(); i++) {
            arrayList.add(jSONArray.getString(i));
        }
        return arrayList;
    }

    public static <T> boolean l(T t, T t2) {
        return t == null ? t2 == null : t.equals(t2);
    }

    public static boolean n(Uri uri) {
        return uri != null && (Constants.HTTP.equalsIgnoreCase(uri.getScheme()) || Constants.HTTPS.equalsIgnoreCase(uri.getScheme()) || "fbstaging".equalsIgnoreCase(uri.getScheme()));
    }

    public static boolean o(Uri uri) {
        return uri != null && FirebaseAnalytics.Param.CONTENT.equalsIgnoreCase(uri.getScheme());
    }

    public static boolean p(Uri uri) {
        return uri != null && KS2SEventNative.SCHEME_FILE.equalsIgnoreCase(uri.getScheme());
    }

    /* JADX WARNING: Removed duplicated region for block: B:12:0x0029  */
    public static long q(Uri uri) {
        Cursor cursor;
        Throwable th;
        try {
            cursor = wpc.getApplicationContext().getContentResolver().query(uri, null, null, null, null);
            try {
                int columnIndex = cursor.getColumnIndex("_size");
                cursor.moveToFirst();
                long j = cursor.getLong(columnIndex);
                if (cursor != null) {
                    cursor.close();
                }
                return j;
            } catch (Throwable th2) {
                th = th2;
                if (cursor != null) {
                }
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            cursor = null;
            if (cursor != null) {
                cursor.close();
            }
            throw th;
        }
    }

    public static <T> Collection<T> w(T... tArr) {
        return Collections.unmodifiableCollection(Arrays.asList(tArr));
    }

    public static <T> List<T> x(T... tArr) {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < 2; i++) {
            T t = tArr[i];
            if (t != null) {
                arrayList.add(t);
            }
        }
        return arrayList;
    }
}